package xing.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/********************************
 * 文 件 名 :SchedulingConfiguration.java
 * 创 建 人：陈天龙
 * 日    期：2017/8/23
 * 描   述：定时任务线程池配置
 * 版 本 号：v1.0.0
 ********************************/
@Configuration
@EnableScheduling
public class SchedulingConfiguration implements SchedulingConfigurer {

    private @Value("${spring.scheduling.pool.corePoolSize}") Integer corePoolSize;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(taskExecutor());
    }

    @Bean
    public Executor taskExecutor() {
        return Executors.newScheduledThreadPool(corePoolSize);
    }
}
